home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 124 / cd-rom 124.iso / edu / tuxmath / tuxmathscrabble / tuxmathscrabble.exe / asymptopia / tuxmathscrabble.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2003-11-16  |  20.2 KB  |  731 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.2)
  3.  
  4. import os
  5. import pygame
  6. import sys
  7. from pygame.locals import *
  8. from random import random
  9. from asymptopia.myutil import load_image
  10. from asymptopia.Board import *
  11. from asymptopia.Spot import *
  12. from asymptopia.myutil import *
  13. from asymptopia.Tile import *
  14. from asymptopia.Button import *
  15. from asymptopia.Validator import *
  16. from asymptopia.Localizer import *
  17. from asymptopia.Tux import *
  18. from asymptopia.Animator import *
  19. from asymptopia.AnimatedChar import *
  20. from asymptopia.CuckooManeuvers import CuckooManeuvers
  21. from asymptopia.TuxManeuvers import TuxManeuvers
  22.  
  23. try:
  24.     for sitepkgdir in sys.path:
  25.         if sitepkgdir[-13:] == 'site-packages':
  26.             break
  27.         
  28. except:
  29.     pass
  30.  
  31. if not (pygame.font):
  32.     print 'Warning, fonts disabled'
  33.  
  34. if not (pygame.mixer):
  35.     print 'Warning, sound disabled'
  36.  
  37. M = 13
  38. N = 17
  39. W = 800
  40. H = 600
  41. DEFAULT_LEVEL = 5
  42. WAIT_TIME = 100
  43.  
  44. class TuxMathScrabble:
  45.     
  46.     def __init__(self, level):
  47.         pygame.init()
  48.         screen = pygame.display.set_mode((W, H))
  49.         pygame.display.set_caption('www.asymptopia.com')
  50.         pygame.mouse.set_visible(1)
  51.         self.pyfont = pygame.font.Font(os.path.join(sitepkgdir, 'asymptopia/font/freesansbold.ttf'), 16)
  52.         self.LEVEL = level
  53.         self.tux_wait_counter = 0
  54.         slide1 = load_sound('asymptopia/sounds/slide01.wav')
  55.         slide2 = load_sound('asymptopia/sounds/slide02.wav')
  56.         boink = load_sound('asymptopia/sounds/bong05.wav')
  57.         kerplunk = load_sound('asymptopia/sounds/beep07.wav')
  58.         win_sound_01 = load_sound('asymptopia/sounds/sparcle.wav')
  59.         win_sound_02 = load_sound('asymptopia/sounds/bullcall.wav')
  60.         win_sound_03 = load_sound('asymptopia/sounds/aooga.wav')
  61.         lose_sound = load_sound('asymptopia/sounds/foghorn2.wav')
  62.         pop01 = load_sound('asymptopia/sounds/pop01.wav')
  63.         pop02 = load_sound('asymptopia/sounds/pop01.wav')
  64.         animator = Animator()
  65.         self.tuxManeuvers = TuxManeuvers()
  66.         AnimatedTux = AnimatedChar(self.tuxManeuvers.getSequencesPyld(), W / 2, 100)
  67.         animator.add_char('Tux', AnimatedTux)
  68.         tuxManeuversPyld = self.tuxManeuvers.getManeuversPyld()
  69.         for key in tuxManeuversPyld:
  70.             animator.define_maneuver(key, tuxManeuversPyld[key])
  71.         
  72.         self.cuckooManeuvers = CuckooManeuvers()
  73.         AnimatedTiles = []
  74.         AnimatedTileNames = []
  75.         for idx in range(N):
  76.             AnimatedTiles.append(AnimatedChar(self.cuckooManeuvers.getSequencesPyld(), -25, -25))
  77.             new_name = 'Tile_%02d' % idx
  78.             AnimatedTileNames.append(new_name)
  79.             animator.add_char(AnimatedTileNames[idx], AnimatedTiles[idx])
  80.         
  81.         cuckooManeuversPyld = self.cuckooManeuvers.getManeuversPyld()
  82.         for key in cuckooManeuversPyld:
  83.             animator.define_maneuver(key, cuckooManeuversPyld[key])
  84.         
  85.         help_button = Button('asymptopia/images/help.gif')
  86.         help_button.rect.center = (W - 70, H - 285)
  87.         credit_button = Button('asymptopia/images/credits.gif')
  88.         credit_button.rect.center = (W - 70, H - 235)
  89.         skip_button = Button('asymptopia/images/skip.gif')
  90.         skip_button.rect.center = (W - 70, H - 135)
  91.         ready_button = Button('asymptopia/images/ready.gif')
  92.         ready_button.rect.center = (W - 70, H - 185)
  93.         l1_button = Button('asymptopia/images/level_one.gif')
  94.         l1_button.rect.center = (65, H - 135)
  95.         l2_button = Button('asymptopia/images/level_two.gif')
  96.         l2_button.rect.center = (65, H - 185)
  97.         l3_button = Button('asymptopia/images/level_three.gif')
  98.         l3_button.rect.center = (65, H - 235)
  99.         l4_button = Button('asymptopia/images/level_four.gif')
  100.         l4_button.rect.center = (65, H - 285)
  101.         buttongroup = pygame.sprite.Group([
  102.             help_button,
  103.             ready_button,
  104.             skip_button,
  105.             credit_button,
  106.             l1_button,
  107.             l2_button,
  108.             l3_button,
  109.             l4_button])
  110.         buttons = pygame.sprite.RenderPlain(buttongroup)
  111.         background = pygame.Surface(screen.get_size())
  112.         background = background.convert()
  113.         background.fill((0, 150, 100))
  114.         level_indicator = pygame.Surface((10, 10))
  115.         level_indicator = level_indicator.convert()
  116.         level_indicator.fill((255, 0, 0))
  117.         board = Board(M, N, W / 2, H / 2, None, 'asymptopia/images/new_spot.gif')
  118.         boardspots = pygame.sprite.RenderPlain(board.get_spots())
  119.         if self.LEVEL == 3 or self.LEVEL == 4:
  120.             NTRAYSPOTS = 12
  121.             NNUMBERS = 7
  122.         else:
  123.             NTRAYSPOTS = 10
  124.             NNUMBERS = 6
  125.         tray = Board(1, NTRAYSPOTS, W / 2, H - 40, None, 'asymptopia/images/new_spot.gif')
  126.         trayspots = pygame.sprite.RenderPlain(tray.get_spots())
  127.         submission = Board(M, N, W / 2, H / 2, None, 'asymptopia/images/new_spot.gif')
  128.         submissionspots = pygame.sprite.RenderPlain()
  129.         target = pygame.sprite.RenderClear()
  130.         validator = Validator(board, self)
  131.         localizer = Localizer(board, self)
  132.         self.NTRAYSPOTS = NTRAYSPOTS
  133.         self.NNUMBERS = NNUMBERS
  134.         self.localizer = localizer
  135.         self.validator = validator
  136.         self.screen = screen
  137.         self.boink = boink
  138.         self.kerplunk = kerplunk
  139.         self.slide1 = slide1
  140.         self.slide2 = slide2
  141.         self.win_sound_01 = win_sound_01
  142.         self.win_sound_02 = win_sound_02
  143.         self.win_sound_03 = win_sound_03
  144.         self.lose_sound = lose_sound
  145.         self.submissionspots = submissionspots
  146.         self.submission = submission
  147.         self.board = board
  148.         self.boardspots = boardspots
  149.         self.tray = tray
  150.         self.trayspots = trayspots
  151.         self.target = target
  152.         self.background = background
  153.         self.level_indicator = level_indicator
  154.         self.buttons = buttons
  155.         self.help_button = help_button
  156.         self.ready_button = ready_button
  157.         self.skip_button = skip_button
  158.         self.credit_button = credit_button
  159.         self.l1_button = l1_button
  160.         self.l2_button = l2_button
  161.         self.l3_button = l3_button
  162.         self.l4_button = l4_button
  163.         self.animator = animator
  164.         self.AnimatedTux = AnimatedTux
  165.         self.AnimatedTiles = AnimatedTiles
  166.         self.AnimatedTileNames = AnimatedTileNames
  167.         self.num_animated_tiles = 0
  168.         self.animation_in_progress = 0
  169.         self.tuxturn = 0
  170.         tuxtray = Board(1, NTRAYSPOTS, W / 2, 70, None, 'asymptopia/images/new_spot.gif')
  171.         tuxtrayspots = pygame.sprite.RenderPlain(tuxtray.get_spots())
  172.         self.tuxtrayspots = tuxtrayspots
  173.         self.tuxtray = tuxtray
  174.         tux = Tux(self)
  175.         self.tux = tux
  176.  
  177.     
  178.     def draw_tiles(self, spots, who):
  179.         imgnames = [
  180.             'zero',
  181.             'one',
  182.             'two',
  183.             'three',
  184.             'four',
  185.             'five',
  186.             'six',
  187.             'seven',
  188.             'eight',
  189.             'nine',
  190.             'ten',
  191.             'eleven',
  192.             'twelve',
  193.             'thirteen',
  194.             'fourteen',
  195.             'fifteen',
  196.             'twenty']
  197.         for spot in spots:
  198.             if spot.occupied():
  199.                 continue
  200.             
  201.             if spot.getMN()[1] < self.NNUMBERS:
  202.                 if self.LEVEL == 4:
  203.                     int_val = int(16 * random()) + 1
  204.                 elif self.LEVEL == 3:
  205.                     int_val = int(10 * random()) + 1
  206.                 elif self.LEVEL == 2:
  207.                     int_val = int(15 * random())
  208.                 else:
  209.                     int_val = int(10 * random())
  210.                 str_val = `int_val` + '.0'
  211.                 if int_val == 16:
  212.                     str_val = '20.0'
  213.                 
  214.                 if who == 'tux':
  215.                     fname = 'asymptopia/images/tux_' + imgnames[int_val] + '.gif'
  216.                 else:
  217.                     fname = 'asymptopia/images/' + imgnames[int_val] + '.gif'
  218.             elif spot.getMN()[1] < self.NTRAYSPOTS - 1:
  219.                 opnames = [
  220.                     'new_plus',
  221.                     'new_minus',
  222.                     'new_mult',
  223.                     'new_divide']
  224.                 if self.LEVEL == 4:
  225.                     idx = int(4 * random())
  226.                 elif self.LEVEL == 3:
  227.                     idx = int(3 * random())
  228.                 else:
  229.                     idx = int(2 * random())
  230.                 int_val = None
  231.                 if opnames[idx] == 'new_plus':
  232.                     str_val = '+'
  233.                 elif opnames[idx] == 'new_minus':
  234.                     str_val = '-'
  235.                 elif opnames[idx] == 'new_mult':
  236.                     str_val = '*'
  237.                 elif opnames[idx] == 'new_divide':
  238.                     str_val = '/'
  239.                 
  240.                 if who == 'tux':
  241.                     opnames[idx] = 'tux_' + opnames[idx]
  242.                 
  243.                 fname = 'asymptopia/images/' + opnames[idx] + '.gif'
  244.             elif who == 'tux':
  245.                 fname = 'asymptopia/images/tux_new_equal.gif'
  246.             else:
  247.                 fname = 'asymptopia/images/new_equal.gif'
  248.             int_val = None
  249.             str_val = '='
  250.             tile = Tile(fname, int_val, str_val)
  251.             spot.take_guest(tile, 1)
  252.             tile.saved_center = spot.rect.center
  253.         
  254.  
  255.     
  256.     def play(self):
  257.         AnimatedTiles = self.AnimatedTiles
  258.         AnimatedTileNames = self.AnimatedTileNames
  259.         AnimatedTux = self.AnimatedTux
  260.         animator = self.animator
  261.         tux = self.tux
  262.         validator = self.validator
  263.         localizer = self.localizer
  264.         screen = self.screen
  265.         boink = self.boink
  266.         kerplunk = self.kerplunk
  267.         slide1 = self.slide1
  268.         slide2 = self.slide2
  269.         win_sound_01 = self.win_sound_01
  270.         win_sound_02 = self.win_sound_02
  271.         win_sound_03 = self.win_sound_03
  272.         lose_sound = self.lose_sound
  273.         submissionspots = self.submissionspots
  274.         submission = self.submission
  275.         board = self.board
  276.         boardspots = self.boardspots
  277.         tray = self.tray
  278.         trayspots = self.trayspots
  279.         target = self.target
  280.         background = self.background
  281.         level_indicator = self.level_indicator
  282.         buttons = self.buttons
  283.         help_button = self.help_button
  284.         ready_button = self.ready_button
  285.         skip_button = self.skip_button
  286.         credit_button = self.credit_button
  287.         l1_button = self.l1_button
  288.         l2_button = self.l2_button
  289.         l3_button = self.l3_button
  290.         l4_button = self.l4_button
  291.         tuxtrayspots = self.tuxtrayspots
  292.         tuxtray = self.tuxtray
  293.         self.draw_tiles(tray.get_spots(), 'player')
  294.         self.draw_tiles(tuxtray.get_spots(), 'tux')
  295.         tuxturn = self.tuxturn
  296.         num_animated_tiles = self.num_animated_tiles
  297.         animation_in_progress = self.animation_in_progress
  298.         self.tuxscore = 0
  299.         self.playerscore = 0
  300.         coin = 0
  301.         if coin == 0:
  302.             animator.start_maneuver('Tux', 'tux_welcome_maneuver_01')
  303.         
  304.         animation_in_progress = 1
  305.         tux_move_progress = 0
  306.         tile_animation_in_progress = 0
  307.         num_animated_tiles = 0
  308.         while 1:
  309.             num_animated_tiles = self.num_animated_tiles
  310.             animation_in_progress = self.animation_in_progress
  311.             if tuxturn == 1 and tux_move_progress == 0 and animation_in_progress == 0 and num_animated_tiles == 0:
  312.                 coin = int(random() * 4)
  313.                 if coin == 0:
  314.                     animator.start_maneuver('Tux', 'tux_get_up_maneuver_01')
  315.                 elif coin == 1:
  316.                     animator.start_maneuver('Tux', 'tux_get_up_maneuver_02')
  317.                 elif coin == 2:
  318.                     animator.start_maneuver('Tux', 'tux_get_up_maneuver_03')
  319.                 else:
  320.                     animator.start_maneuver('Tux', 'tux_get_up_maneuver_04')
  321.                 tux_move_progress = 1
  322.                 animation_in_progress = 1
  323.             
  324.             if num_animated_tiles == 0 and animation_in_progress == 0 and tuxturn == 1:
  325.                 tux.generate_expressions()
  326.                 tux_finished = 0
  327.                 while tux_finished != 1:
  328.                     tux_submission = tux.generate_options()
  329.                     rlist = tux_submission
  330.                     if tux_submission == None:
  331.                         tux_finished = 1
  332.                         tuxturn = 0
  333.                         self.tux_wait_counter = 0
  334.                         animator.start_maneuver('Tux', 'return_stumped_maneuver')
  335.                         break
  336.                     
  337.                     if rlist == None:
  338.                         pass
  339.                     elif rlist[0][0] == rlist[1][0]:
  340.                         exprtype = 'row'
  341.                     else:
  342.                         exprtype = 'col'
  343.                     
  344.                     try:
  345.                         for idx in range(len(rlist)):
  346.                             tile = tuxtray.get_guest_by_str(rlist[idx][0])
  347.                             spot = submission.take_guestMN(tile, rlist[idx][1], rlist[idx][2])
  348.                             submissionspots.add(spot)
  349.                     except:
  350.                         raw_input()
  351.  
  352.                     board.increment_num_commited()
  353.                     for spot in submissionspots.sprites():
  354.                         for board_spot in board.get_spots():
  355.                             if board_spot.rect.center == spot.rect.center:
  356.                                 tile = spot.pop_guest()
  357.                                 board_spot.take_guest(tile, 1)
  358.                                 board_spot.lock()
  359.                                 submission.remove(spot)
  360.                             
  361.                         
  362.                     
  363.                     submissionspots.empty()
  364.                     self.draw_tiles(tuxtray.get_spots(), 'tux')
  365.                     tux_finished = 1
  366.                     tuxturn = 0
  367.                     coin = int(random() * 3)
  368.                     if coin == 0:
  369.                         animator.start_maneuver('Tux', 'return_skating_maneuver')
  370.                     elif coin == 1:
  371.                         animator.start_maneuver('Tux', 'tux_go_back_from_tray_maneuver_01')
  372.                     else:
  373.                         animator.start_maneuver('Tux', 'tux_go_back_from_tray_maneuver_02')
  374.             
  375.             for event in pygame.event.get():
  376.                 if event.type == QUIT:
  377.                     return 0
  378.                 elif event.type == KEYDOWN and event.key == K_ESCAPE:
  379.                     return 0
  380.                 elif event.type == KEYDOWN and event.key == K_F1:
  381.                     display_surface = pygame.display.get_surface()
  382.                     pygame.image.save(display_surface, os.path.join(os.environ['HOME'], 'tuxmathscrabble.bmp'))
  383.                 elif event.type == MOUSEBUTTONDOWN:
  384.                     self.tux_wait_counter = 0
  385.                     if help_button.rect.collidepoint(pygame.mouse.get_pos()):
  386.                         (help_image, rect) = load_image('asymptopia/images/help_splash.gif')
  387.                         self.screen.blit(help_image, (0, 0))
  388.                         pygame.display.flip()
  389.                         while 1:
  390.                             breakout = 0
  391.                             for event in pygame.event.get():
  392.                                 if event.type == KEYDOWN:
  393.                                     breakout = 1
  394.                                 elif event.type == MOUSEBUTTONDOWN:
  395.                                     breakout = 1
  396.                                 
  397.                             
  398.                             if breakout:
  399.                                 break
  400.                             
  401.                     
  402.                     if credit_button.rect.collidepoint(pygame.mouse.get_pos()):
  403.                         (credit_image, rect) = load_image('asymptopia/images/credit_splash.gif')
  404.                         self.screen.blit(credit_image, (0, 0))
  405.                         pygame.display.flip()
  406.                         while 1:
  407.                             breakout = 0
  408.                             for event in pygame.event.get():
  409.                                 if event.type == KEYDOWN:
  410.                                     breakout = 1
  411.                                 elif event.type == MOUSEBUTTONDOWN:
  412.                                     breakout = 1
  413.                                 
  414.                             
  415.                             if breakout:
  416.                                 break
  417.                             
  418.                     
  419.                     if l1_button.rect.collidepoint(pygame.mouse.get_pos()):
  420.                         self.LEVEL = 1
  421.                         return 1
  422.                     
  423.                     if l2_button.rect.collidepoint(pygame.mouse.get_pos()):
  424.                         self.LEVEL = 2
  425.                         return 2
  426.                     
  427.                     if l3_button.rect.collidepoint(pygame.mouse.get_pos()):
  428.                         self.LEVEL = 3
  429.                         return 3
  430.                     
  431.                     if l4_button.rect.collidepoint(pygame.mouse.get_pos()):
  432.                         self.LEVEL = 4
  433.                         return 4
  434.                     elif skip_button.rect.collidepoint(pygame.mouse.get_pos()):
  435.                         if tuxturn == 1 or AnimatedTux.rect[0] < 400:
  436.                             continue
  437.                         else:
  438.                             for spot in submissionspots.sprites():
  439.                                 tile = spot.pop_guest()
  440.                                 if tile:
  441.                                     for spot in tray.get_spots():
  442.                                         if tile.saved_center == spot.rect.center:
  443.                                             spot.take_guest(tile, 1)
  444.                                         
  445.                                     
  446.                                 
  447.                             
  448.                             if len(board.get_listofheads()) == 0:
  449.                                 if not animation_in_progress:
  450.                                     animator.start_maneuver('Tux', 'insist_yougofirst_maneuver')
  451.                                 
  452.                             else:
  453.                                 animator.start_maneuver('Tux', 'head_tilt_right_maneuver')
  454.                                 lose_sound.play()
  455.                                 animation_in_progress = 1
  456.                                 tux_move_progress = 0
  457.                                 submissionspots.empty()
  458.                                 tuxturn = 1
  459.                     elif ready_button.rect.collidepoint(pygame.mouse.get_pos()):
  460.                         if validator.validate(submissionspots.sprites()):
  461.                             board.increment_num_commited()
  462.                             for spot in submissionspots.sprites():
  463.                                 for board_spot in board.get_spots():
  464.                                     if board_spot.rect.center == spot.rect.center and spot.guest:
  465.                                         tile = spot.pop_guest()
  466.                                         rect = board_spot.rect
  467.                                         xc = rect[0] + rect[2] / 2
  468.                                         yc = rect[1] + rect[3] / 2
  469.                                         cuckoo_tile_center = (xc, yc)
  470.                                         AnimatedTiles[num_animated_tiles].set_center(cuckoo_tile_center)
  471.                                         if spot.AMHEAD == 1:
  472.                                             board_spot.AMHEAD = 1
  473.                                             if spot.AMROWEXPR == 1:
  474.                                                 board_spot.AMROWEXPR = 1
  475.                                                 board_spot.ROWEXPRLENGTH = spot.ROWEXPRLENGTH
  476.                                             
  477.                                             if spot.AMCOLEXPR == 1:
  478.                                                 board_spot.AMCOLEXPR = 1
  479.                                                 board_spot.COLEXPRLENGTH = spot.COLEXPRLENGTH
  480.                                             
  481.                                         
  482.                                         board_spot.take_guest(tile, 1)
  483.                                         board_spot.lock()
  484.                                         submission.remove(spot)
  485.                                     
  486.                                 
  487.                                 num_animated_tiles = num_animated_tiles + 1
  488.                             
  489.                             coin = int(random() * 2)
  490.                             if coin == 0:
  491.                                 win_sound_01.play()
  492.                             else:
  493.                                 win_sound_02.play()
  494.                             coin = int(random() * 2)
  495.                             if coin == 0:
  496.                                 animator.start_maneuver('Tux', 'forehead_slap_maneuver')
  497.                             else:
  498.                                 animator.start_maneuver('Tux', 'neck_stretch_maneuver')
  499.                             tux_move_progress = 0
  500.                             animation_in_progress = 1
  501.                             cuckoo_maneuver_names = self.cuckooManeuvers.getManeuverNames()
  502.                             for idx in range(num_animated_tiles):
  503.                                 maneuver_idx = int(random() * len(cuckoo_maneuver_names))
  504.                                 animator.start_maneuver(AnimatedTileNames[idx], cuckoo_maneuver_names[maneuver_idx])
  505.                             
  506.                             self.num_animated_tiles = num_animated_tiles
  507.                             self.draw_tiles(tray.get_spots(), 'player')
  508.                             tuxturn = 1
  509.                         else:
  510.                             for spot in submissionspots.sprites():
  511.                                 tile = spot.pop_guest()
  512.                                 if tile:
  513.                                     for spot in tray.get_spots():
  514.                                         if tile.saved_center == spot.rect.center:
  515.                                             spot.take_guest(tile, 1)
  516.                                         
  517.                                     
  518.                                 
  519.                             
  520.                             if len(self.board.get_listofheads()) > 0:
  521.                                 lose_sound.play()
  522.                                 animator.start_maneuver('Tux', 'head_tilt_left_maneuver')
  523.                                 tux_move_progress = 0
  524.                                 animation_in_progress = 1
  525.                             
  526.                         submissionspots.empty()
  527.                         continue
  528.                     
  529.                     for spot in tray.get_spots():
  530.                         if not (spot.guest):
  531.                             continue
  532.                         
  533.                         if spot.rect.collidepoint(pygame.mouse.get_pos()):
  534.                             slide1.play()
  535.                             target.add(spot.pop_guest())
  536.                         
  537.                     
  538.                     for spot in board.get_spots():
  539.                         if spot.rect.collidepoint(pygame.mouse.get_pos()) and spot.islocked():
  540.                             boink.play()
  541.                         
  542.                     
  543.                     for spot in submission.get_spots():
  544.                         if not spot.occupied():
  545.                             continue
  546.                         
  547.                         if spot.rect.collidepoint(pygame.mouse.get_pos()):
  548.                             guest = spot.pop_guest()
  549.                             submissionspots.remove(spot)
  550.                             slide1.play()
  551.                             target.add(guest)
  552.                         
  553.                     
  554.                 elif event.type == MOUSEBUTTONUP:
  555.                     if len(target.sprites()) > 0:
  556.                         for spot in submission.get_spots():
  557.                             if spot.rect.collidepoint(target.sprites()[0].rect.center):
  558.                                 if spot.occupied():
  559.                                     continue
  560.                                 
  561.                                 spot.take_guest(target.sprites()[0], 1)
  562.                                 kerplunk.play()
  563.                                 submissionspots.add(spot)
  564.                                 target.empty()
  565.                                 break
  566.                             
  567.                         
  568.                         if len(target.sprites()) == 0:
  569.                             continue
  570.                         
  571.                         for spot in board.get_spots():
  572.                             if spot.rect.collidepoint(target.sprites()[0].rect.center):
  573.                                 boink.play()
  574.                                 break
  575.                             
  576.                         
  577.                         if len(target.sprites()) > 0:
  578.                             tile = target.sprites()[0]
  579.                             target.remove(tile)
  580.                             for spot in tray.get_spots():
  581.                                 if tile.saved_center == spot.rect.center:
  582.                                     spot.take_guest(tile, 1)
  583.                                     break
  584.                                 
  585.                             
  586.                         
  587.                     
  588.                 
  589.             
  590.             if not tuxturn:
  591.                 self.tux_wait_counter = self.tux_wait_counter + 1
  592.                 if self.tux_wait_counter > WAIT_TIME and self.animation_in_progress == 0:
  593.                     self.tux_wait_maneuver()
  594.                 else:
  595.                     tux_wait_counter = 0
  596.             
  597.             self.update()
  598.             self.tuxturn = tuxturn
  599.  
  600.     
  601.     def do_one_scratch(self):
  602.         coin = int(random() * 2)
  603.         if coin == 0:
  604.             self.animator.start_maneuver('Tux', 'one_scratchl_maneuver')
  605.         else:
  606.             self.animator.start_maneuver('Tux', 'one_scratchr_maneuver')
  607.         self.tux_move_progress = 0
  608.         self.update()
  609.         self.update()
  610.         self.update()
  611.         self.update()
  612.  
  613.     
  614.     def tux_wait_maneuver(self):
  615.         idx = int(random() * 9)
  616.         if idx == 0:
  617.             self.animator.start_maneuver('Tux', 'head_tilt_left_maneuver')
  618.         
  619.         if idx == 1:
  620.             self.animator.start_maneuver('Tux', 'head_tilt_right_maneuver')
  621.         
  622.         if idx == 2:
  623.             self.animator.start_maneuver('Tux', 'neck_stretch_maneuver')
  624.         
  625.         if idx == 3:
  626.             self.animator.start_maneuver('Tux', 'tux_flapper_maneuver')
  627.         
  628.         if idx == 5:
  629.             self.animator.start_maneuver('Tux', 'hop_in_place_maneuver')
  630.         
  631.         if idx == 6:
  632.             self.animator.start_maneuver('Tux', 'walkoff_stage_right_maneuver')
  633.         
  634.         if idx == 7:
  635.             self.animator.start_maneuver('Tux', 'neck_squash_tiltleftright_maneuver')
  636.         
  637.         if idx == 8:
  638.             self.animator.start_maneuver('Tux', 'neck_squash_hop_in_place_maneuver')
  639.         
  640.         self.tux_move_progress = 0
  641.         self.tux_wait_counter = 0
  642.         self.update()
  643.  
  644.     
  645.     def update(self):
  646.         screen = self.screen
  647.         background = self.background
  648.         buttons = self.buttons
  649.         boardspots = self.boardspots
  650.         trayspots = self.trayspots
  651.         submissionspots = self.submissionspots
  652.         target = self.target
  653.         AnimatedTux = self.AnimatedTux
  654.         animation_in_progress = self.animation_in_progress
  655.         AnimatedTiles = self.AnimatedTiles
  656.         tuxtrayspots = self.tuxtrayspots
  657.         for event in pygame.event.get():
  658.             if event.type == QUIT:
  659.                 return 0
  660.             elif event.type == KEYDOWN and event.key == K_ESCAPE:
  661.                 return 0
  662.             
  663.         
  664.         screen.blit(background, (0, 0))
  665.         if self.LEVEL == 1:
  666.             b = self.l1_button
  667.         elif self.LEVEL == 2:
  668.             b = self.l2_button
  669.         elif self.LEVEL == 3:
  670.             b = self.l3_button
  671.         elif self.LEVEL == 4:
  672.             b = self.l4_button
  673.         
  674.         screen.blit(self.level_indicator, (10, b.rect[1] + b.rect[3] / 3))
  675.         tuxscorestring = " Tux's Score: %03d" % self.tuxscore
  676.         screen.blit(self.pyfont.render(tuxscorestring, 1, (255, 255, 0, 0), (0, 150, 100)), (20, 30))
  677.         playerscorestring = ' Your Score : %03d' % self.playerscore
  678.         screen.blit(self.pyfont.render(playerscorestring, 1, (255, 255, 0, 0), (0, 150, 100)), (20, 60))
  679.         if self.LEVEL == 3:
  680.             if self.tuxturn == 1:
  681.                 tuxturnstring = "<-- Tux's Turn"
  682.                 screen.blit(self.pyfont.render(tuxturnstring, 1, (255, 255, 0, 0), (0, 150, 100)), (W - 180, 45))
  683.             else:
  684.                 yourturnstring = '<-- Your Turn!'
  685.                 screen.blit(self.pyfont.render(yourturnstring, 1, (255, 255, 0, 0), (0, 150, 100)), (W - 180, 530))
  686.         elif self.tuxturn == 1:
  687.             tuxturnstring = "<-- Tux's Turn"
  688.             screen.blit(self.pyfont.render(tuxturnstring, 1, (255, 255, 0, 0), (0, 150, 100)), (W - 200, 45))
  689.         else:
  690.             yourturnstring = '<-- Your Turn!'
  691.             screen.blit(self.pyfont.render(yourturnstring, 1, (255, 255, 0, 0), (0, 150, 100)), (W - 200, 530))
  692.         buttons.draw(screen)
  693.         boardspots.draw(screen)
  694.         submissionspots.draw(screen)
  695.         trayspots.draw(screen)
  696.         tuxtrayspots.draw(screen)
  697.         if len(target.sprites()) > 0:
  698.             target.sprites()[0].update()
  699.             target.draw(screen)
  700.         
  701.         rval = AnimatedTux.update()
  702.         screen.blit(AnimatedTux.image, (AnimatedTux.rect[0], AnimatedTux.rect[1]))
  703.         sound = AnimatedTux.get_sound()
  704.         if sound:
  705.             sound.play()
  706.         
  707.         if AnimatedTux.get_dest():
  708.             self.animation_in_progress = 1
  709.         else:
  710.             self.animation_in_progress = 0
  711.         if self.num_animated_tiles > 0:
  712.             self.num_animated_tiles = 0
  713.             for tile in AnimatedTiles:
  714.                 if not tile.get_dest():
  715.                     tile.set_center((0, 0))
  716.                 else:
  717.                     self.num_animated_tiles = self.num_animated_tiles + 1
  718.                     rval = tile.update()
  719.                     screen.blit(tile.image, (tile.rect[0], tile.rect[1]))
  720.             
  721.         
  722.         pygame.display.flip()
  723.         if AnimatedTux.get_dest():
  724.             if AnimatedTux.rect[0] < 0:
  725.                 AnimatedTux.set_center((730, 100))
  726.             
  727.             time.sleep(AnimatedTux.get_timeout())
  728.         
  729.  
  730.  
  731.